_realname=nuspell
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.2.0
pkgrel=3
pkgdesc="Fast and safe spellchecking C++ library (mingw-w64)"
arch=('any')
url="https://nuspell.github.io/"
license=(LGPL3+)
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-catch")
depends=("${MINGW_PACKAGE_PREFIX}-icu")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/nuspell/nuspell/archive/v${pkgver}.tar.gz")
sha256sums=('01804d490bec517748ee49fa2f1249f4c99380c26335e32082cdaa02b5b2b4dc')
sha512sums=('ae9157e9753868c002ed69a765fb705d29d993f3940e11efbc2699778a8b1abee2eb7daa0ff51187b899d6935a215a24662e5b52ec1ef5c644e90a0245f7583d')

build() {
  local build_dir="${srcdir}/build-${MINGW_CHOST}"
  [[ -d "$build_dir" ]] && rm -rf "$build_dir"
  mkdir "$build_dir" && cd "$build_dir"
  
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe ../"${_realname}-${pkgver}" \
    -G "MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  ctest
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install

  # Licenses
  cd "${srcdir}/${_realname}-${pkgver}"
  install -Dm644 COPYING      "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 COPYING.LESSER "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LESSER"
}
